﻿/**
 * Created by hobtdto on 2017/7/8.
 */
(function($, window, document, undefined) {

var settings={
    'linkchar': ':',
    'number': '1'
}
var macAddress;
var MacAddress=function (ele, opt) {
    this.element = ele,
    defaults = {
        'linkchar': ':',
        'number': '1'
    };
    settings = $.extend(defaults, opt);

}

MacAddress.prototype={
    GetMac:function () {
        var strArray =new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
        var adrStr = ''
        for(var i=0;i<13;i++)
        {
            var index='0';
            if(i==1){
                var indexArray=new Array(0,2, 4, 6, 8, 10, 12, 14);
                index=indexArray[Math.floor(Math.random()*8)];

            }else{
                index = Math.floor(Math.random()*16)
            }
            adrStr = adrStr +strArray[index];
        }

        return macAddress.Stitching(adrStr);
    },
    Stitching:function (str) {
        var macStr='';
        for(var i=0;i<6;i++){
            macStr=macStr+str.substr(i*2,2)+settings.linkchar;
        }
       return macStr.substr(0,17);
    }

}

    $.fn.GetMacAddress = function(options) {

        macAddress=new MacAddress(this,options)
        if(settings.number=='1'){
            return  macAddress.GetMac();
        }
        var macs='';
        for(var i=0;i<settings.number;i++){
            if(i==settings.number-1){
                macs+=macAddress.GetMac();
                return macs;
            }
            macs+=macAddress.GetMac()+'<br/>';
        }
}
})(jQuery, window, document);